import { IPSSysDBScheme } from './ipssys-dbscheme';
import { IPSSysDBTable } from './ipssys-dbtable';
import { IPSSysSFPlugin } from '../res/ipssys-sfplugin';
import { IPSSysModelGroup } from '../system/ipssys-model-group';
import { IPSSystemModule } from '../system/ipssystem-module';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSSysDBSchemeImpl extends PSModelObjectImpl implements IPSSysDBScheme {
  protected allpssysdbtables: IPSSysDBTable[] | null = null;

  getAllPSSysDBTables(): IPSSysDBTable[] | null {
    if (this.allpssysdbtables == null) {
      this.allpssysdbtables = this.fillChildListModel(this.M.getAllPSSysDBTables, 'database.IPSSysDBTable') as IPSSysDBTable[];
    }
    return this.allpssysdbtables;
  }

  get allPSSysDBTables(): IPSSysDBTable[] | null {
    return this.getAllPSSysDBTables();
  }

  findPSSysDBTable(objKey: any): IPSSysDBTable | null {
    return this.getPSModel5('database.IPSSysDBTable', this.getAllPSSysDBTables(), objKey) as IPSSysDBTable;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get codeName2(): string {
    return this.M.codeName2;
  }

  get dBInstTag(): string {
    return this.M.dBInstTag;
  }

  get dSLink(): 'DEFAULT' | 'DB2' | 'DB3' | 'DB4' | 'DB5' | 'DB6' | 'DB7' | 'DB8' | 'DB9' | 'DB10' | 'DB11' | 'DB12' {
    return this.M.dSLink;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected pssysmodelgroup: IPSSysModelGroup | null = null;

  getPSSysModelGroup(): IPSSysModelGroup | null {
    if (this.pssysmodelgroup != null) return this.pssysmodelgroup;
    const value = this.M.getPSSysModelGroup;
    if (value == null) {
      return null;
    }
    this.pssysmodelgroup = this.getPSModel4('system.IPSSysModelGroup', value, 'getPSSysModelGroup') as IPSSysModelGroup;
    return this.pssysmodelgroup;
  }

  get psSysModelGroup(): IPSSysModelGroup | null {
    return this.getPSSysModelGroup();
  }

  getPSSysModelGroupMust(): IPSSysModelGroup {
    const value = this.getPSSysModelGroup();
    if (value == null) {
      throw new Error('未指定系统模型组');
    }
    return value;
  }

  protected pssyssfplugin: IPSSysSFPlugin | null = null;

  getPSSysSFPlugin(): IPSSysSFPlugin | null {
    if (this.pssyssfplugin != null) return this.pssyssfplugin;
    const value = this.M.getPSSysSFPlugin;
    if (value == null) {
      return null;
    }
    this.pssyssfplugin = this.getPSModel4('res.IPSSysSFPlugin', value, 'getPSSysSFPlugin') as IPSSysSFPlugin;
    return this.pssyssfplugin;
  }

  get psSysSFPlugin(): IPSSysSFPlugin | null {
    return this.getPSSysSFPlugin();
  }

  getPSSysSFPluginMust(): IPSSysSFPlugin {
    const value = this.getPSSysSFPlugin();
    if (value == null) {
      throw new Error('未指定后台扩展插件');
    }
    return value;
  }

  protected pssystemmodule: IPSSystemModule | null = null;

  getPSSystemModule(): IPSSystemModule | null {
    if (this.pssystemmodule != null) return this.pssystemmodule;
    const value = this.M.getPSSystemModule;
    if (value == null) {
      return null;
    }
    this.pssystemmodule = this.getPSModel4('system.IPSSystemModule', value, 'getPSSystemModule') as IPSSystemModule;
    return this.pssystemmodule;
  }

  get psSystemModule(): IPSSystemModule | null {
    return this.getPSSystemModule();
  }

  getPSSystemModuleMust(): IPSSystemModule {
    const value = this.getPSSystemModule();
    if (value == null) {
      throw new Error('未指定系统模块');
    }
    return value;
  }

  get saaSDCIdColumnName(): string {
    return this.M.saaSDCIdColumnName;
  }

  get saaSDataIdColumnName(): string {
    return this.M.saaSDataIdColumnName;
  }

  get schemeTag(): string {
    return this.M.schemeTag;
  }

  get schemeTag2(): string {
    return this.M.schemeTag2;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get autoExtendModel(): boolean {
    return this.M.autoExtendModel != null ? this.M.autoExtendModel : false;
  }

  get existingModel(): boolean {
    return this.M.existingModel != null ? this.M.existingModel : false;
  }

  get pubIndex(): boolean {
    return this.M.pubIndex != null ? this.M.pubIndex : false;
  }

  get cls(): string {
    return 'PSSysDBSchemeImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'database.IPSSysDBScheme') return true;
    return super.instanceof(cls);
  }
}
